<template>
  <view>

  </view>
</template>

<script>
  export default {
    data() {
      return {

      }
    },
    onTabItemTap() {
      let token = uni.getStorageSync('token') || null;
      if (!token) {
        uni.reLaunch({
          url: '/pages/login/login'
        })
        return;
      }
      uni.scanCode({
        onlyFromCamera: true,
        scanType: 'qrCode',
        success: function(res) {
          let str = res.result;
          let index = str.lastIndexOf('/');
          let code = str.substr(index + 1, str.length);
          
          uni.navigateTo({
            url: '../rechargeCabinet/rechargeCabinet?code=' + code
          })
        },
        fail: (err) => {
          console.log(err)
        }
      });
    },
    methods: {
      scancode() {
        // 允许从相机和相册扫码
        uni.scanCode({
          success: function(res) {
            console.log('条码类型：' + res.scanType);
            console.log('条码内容：' + res.result);
          }
        });
      }
    }
  }
</script>

<style>

</style>
